# -*- coding: utf-8 -*-
"""
Created on Tue Feb 19 14:55:43 2013

@author: aponteeduarddo@gmail.com
Copyright Eduardo Aponte 2013.
"""

from mex_binder import binder_py


mx_eyelink_close = binder_py('mx_eyelink_close')
mx_eyelink_close.mx_c.headers = ['<eyelink.h>','"mex.h"','"utils.h"']
mx_eyelink_close.bindo += ['utils.o']
mx_eyelink_close.mx_c.code = '''

INT16 _main( INT16 code  )
{
    return eyelink_close( code ); 
}


void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    double *status;
    int code;
    mwSize td[2] = {1,1};
    
    /* Verify input arguments. */
    if(nrhs != 1 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 1 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
    
    if ( isscalar( *prhs ) ){
        INT16 scalar;
        /* Returns the scalar, casts to int if necessary. Returns 0 if */
        /* input is complex. */
        if ( returnscalar( *prhs, &code ) != 1 )
        mexErrMsgTxt("Complex data is not supported.");                        
    } else {
        mexErrMsgTxt("send_msg should be a scalar.");                        
    }
    
    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status  = mxGetPr(plhs[0]);    
    *status = (double ) _main( (INT16 ) code );

    return;
    
}


'''

mx_eyelink_close.mx_c.mdoc = \
'''function [ status ] = mx_eyelink_close( send_msg )
%MX_EYELINK_CLOSE Sends a disconnect message to the EyeLink tracker, resets
% the link data system.
%
% Parameters:
% send_msg 	Usually <send_msg> is 1. However, 0 can be used to reset the eyelink
% system if it is listening on a broadcast session.
% Returns:
% 0 if successful, otherwise link error.
%
'''
mx_eyelink_close.write_c()
mx_eyelink_close.write_m()
mx_eyelink_close.compile()
mx_eyelink_close.write_sh()
mx_eyelink_close.ocompile()

